<template>
	<view>
		<swiper indicator-dots>
			<swiper-item  v-for="(item,index) in swiperData" :key="index">
				<image :src="item.src"></image>
			</swiper-item>
		</swiper>
		<view class="box1">
			<view class="price">
				<text>￥{{goodsDetail.sell_price}}</text>
				<text>￥{{goodsDetail.market_price}}</text>
			</view>
			<view  class="goodsName">
				{{goodsDetail.title}}
			</view>
		</view>
		<view class="line"></view>
		<view class="box2">
			<text space="emsp">货号: {{goodsDetail.goods_no}}</text>
			<text space="emsp">库存: {{goodsDetail.stock_quantity}}</text>
		</view>
		<view class="line"></view>
		<!-- 详情介绍 -->
		<view class="box3">
			<view class="title">详情介绍</view>
			<view class="detailContent">
				<rich-text :nodes="goodsDetalContent.content"></rich-text>
			</view>
		</view>
		<uni-goods-nav class="goodsNav" :fill="true"  :options="options" :buttonGroup="buttonGroup"  @click="onClick" @buttonClick="buttonClick" />
	</view>
</template>
<script>
	import uniGoodsNav from '@/components/uni-goods-nav/uni-goods-nav.vue'
	export default{
		data(){
			return {
				swiperData:[],
				goodsDetail:{},
				goodsDetalContent:{},
				 options: [{
				            icon: 'headphones',
				            text: '客服'
				        }, {
				            icon: 'shop',
				            text: '店铺',
				            info: 2,
				            infoBackgroundColor:'#007aff',
				            infoColor:"red"
				        }, {
				            icon: 'cart',
				            text: '购物车',
				            info: 2
				        }],
				        buttonGroup: [{
				          text: '加入购物车',
				          backgroundColor: '#ff0000',
				          color: '#fff'
				        },
				        {
				          text: '立即购买',
				          backgroundColor: '#ffa200',
				          color: '#fff'
				        }
				        ]
			}
		},
		components:{
			uniGoodsNav
		},
		onLoad(options){
			this.getSwiper(options.id)
			this.getGoodsDetail(options.id)
			this.getGoodsContent(options.id)
		},
		methods:{
			getSwiper(id){
				console.log(id)
				this.$myRequest({
					url:`/api/getthumimages/${id}`	
				}).then((res)=>{
					this.swiperData=res.data.message
					
				})
			},
			// 获取商品详情信息
			getGoodsDetail(id){
				this.$myRequest({
					url:`/api/goods/getinfo/${id}`
				}).then((res)=>{
					this.goodsDetail=res.data.message[0]
				})
			},
			// 获取商品详情内容
			getGoodsContent(id){
				this.$myRequest({
					url:`/api/goods/getdesc/${id}`
				}).then((res)=>{
					console.log(res)
					this.goodsDetalContent=res.data.message[0]
				})
			},
			onClick (e) {
			        // uni.showToast({
			        //   title: `点击${e.content.text}`,
			        //   icon: 'none'
			        // })
					console.log(e)
			      },
			buttonClick (e) {
			        // console.log(e)
			        this.options[2].info++
			      }
		}
	}
</script>

<style lang="scss">
	swiper{
		height: 700rpx;
		image{
			width:100%;
			height:100%;
		}
	}
	.box1{
		margin-top:10rpx;
		padding: 0 10rpx;
		.price{
			font-size:35rpx;
			color:$shop-color;
			line-height:80rpx;
			text:nth-child(2){
				margin-left:30rpx;
				color:#ccc;
				text-decoration: line-through;
				font-size:25rpx;
			}
		}
		.goodsName{
			font-size:35rpx;
			line-height: 60rpx;
			font-weight: 700;
			letter-spacing: 5rpx;
		}
	}
	.line{
		margin-top:10rpx;
		width:100%;
		height:10rpx;
		background-color: #eee;
	}
	.box2{
		padding: 10rpx;
		text{
			display: block;
		}
		text:nth-child(2){
			margin-top:10rpx;
		}
	}
	.box3{
		padding:10rpx;
		.title{
			// height:60rpx;
			line-height:80rpx;
			font-size:40rpx;
			border-bottom: 1px solid #eee;
		}
		.detailContent{
			padding-top:20rpx;
			
		}
	}
	.goodsNav{
		position: fixed;
		bottom: 0;
		left: 0;
		right:0;
		padding:10rpx 0;
	}
</style>